import java.util.Scanner;
import java.util.Stack;

/**
 * @author: gao
 * @create-date: 2025/3/24 15:56
 */

public class Solution {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        int len = s.length();
        for (int i = 0; i < len; i++) {
            char ch1 = s.charAt(i);
            if (ch1 == '(' || ch1 == '[' || ch1 == '{') {
                stack.push(ch1);
            } else {
                if (stack.isEmpty()) {
                    return false;
                }
                char ch2 = stack.peek();
                if ((ch1 == ')' && ch2 == '(') || (ch1 == ']' && ch2 == '[') || (ch1 == '}' && ch2 == '{')) {
                    stack.pop();
                } else {
                    return false;
                }
            }
        }
        if (!stack.isEmpty()) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String s = in.nextLine();
            Solution solution = new Solution();
            System.out.println(solution.isValid(s));
        }
    }
}